package com.aaa.service.impl;

import com.aaa.dao.StaffMapper;
import com.aaa.entity.Staff;
import com.aaa.service.StaffService;
import com.aaa.vo.Result;
import com.aaa.vo.StaffVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @program: keyboard
 * @description:
 * @author: 闫克起2
 * @create: 2024-03-15 14:54
 **/
@Service
public class StaffServiceImpl implements StaffService {
    @Autowired
    private StaffMapper staffMapper;

    @Autowired
    private HttpSession session;
    public Result findByNameAndPwd(String name, String pwd) {
        Staff staff = staffMapper.selectByNameAndPwd(name, pwd);
        if(staff==null){
            return new Result(500,"账户或密码错误",null);
        }
        session.setAttribute("staff",staff);
        return new Result(200,"登录成功",null);
    }

    public Result findByPage(Integer current, Integer pageSize, StaffVo staffVo) {
        //获取当前登录者的信息
        Staff staff = (Staff) session.getAttribute("staff");
        //不是总店的店长
        if(!staff.getBranchid().equals(12138)){
            staffVo.setBranchId(staff.getBranchid());
        }
        //启动分页
        PageHelper.startPage(current,pageSize);
        List<Staff> list= staffMapper.selectByVo(staffVo);
        //封装到PgeInfo
        PageInfo<Staff> pageInfo=new PageInfo<Staff>(list);
        return new Result(200,"查询员工信息成功",pageInfo);
    }
}
